<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
	<base href="<%=basePath%>"><!-- jsp文件头和头部 -->
	<link rel="stylesheet" href="static/css/bootstrap.min.css" />
	<link rel="stylesheet" href="static/css/bootstrap-responsive.min.css"  />
	<link rel="stylesheet" href="static/css/font-awesome.min.css" />
	<link rel="stylesheet" href="static/css/ace.min.css" />
	<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
	<link rel="stylesheet" href="static/css/ace-skins.min.css" />
	<link type="text/css" rel="stylesheet" href="plugins/zTree/2.6/zTreeStyle.css"/>
	<link rel="stylesheet" type="text/css" href="plugins/bootstrap/css/bootstrap-table.css" />
	<link rel="stylesheet" type="text/css" href="plugins/treeTable/themes/vsStyle/treeTable.min.css" />
	</head>
<body>
		
<div class="container-fluid" id="main-container">


<div id="page-content" class="clearfix">
						
  	<div class="row-fluid">
		<div class="table-responsive margin-top-1" >
			<table id="treeTable" class="table table-striped table-bordered table-condensed" >
				<thead><tr ><th style="text-align: center;width: 25%;height: 35px;">区域名称</th><th style="text-align: center;">区域编码</th><th style="text-align: center;width: 20%;">区域类型</th><th style="text-align: center;width: 20%;">备注</th><th style="text-align: center;width: 15%;">操作</th></tr></thead>
				<tbody id="treeTableList" >
				</tbody>
			</table>
		</div>
		<div id="newAdd">
			<a class="btn btn-small btn-success" onclick="add();"style="border-radius: 0px;">新增</a>
		</div>
	</div><!--/#page-content-->
</div><!--/.fluid-container#main-container-->
		

		
		<!-- 引入 -->
		<script src="static/1.9.1/jquery.min.js"></script>
		<script src="static/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="static/js/jquery-ui-1.10.2.custom.min.js"></script>
		<script type="text/javascript" src="static/js/jquery.ui.touch-punch.min.js"></script>
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script>
		<script type="text/javascript" src="static/js/fuelux.spinner.js"></script>
		<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script>
		<script type="text/javascript" src="static/js/bootstrap-timepicker.min.js"></script>
		<script type="text/javascript" src="static/js/date.js"></script>
		<script type="text/javascript" src="static/js/daterangepicker.min.js"></script>
		<script type="text/javascript" src="static/js/bootstrap-colorpicker.min.js"></script>
		<script type="text/javascript" src="static/js/jquery.knob.min.js"></script>
		<script type="text/javascript" src="static/js/jquery.autosize-min.js"></script>
		<script type="text/javascript" src="static/js/jquery.inputlimiter.1.3.1.min.js"></script>
		<script type="text/javascript" src="static/js/jquery.maskedinput.min.js"></script>
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
		<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
		<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
		<script type="text/javascript" src="static/js/jquery.tips.js"></script><!-- 提示框  -->
		<!-- ace scripts -->
		<script src="static/js/ace-elements.min.js"></script>
		<script src="static/js/ace.min.js"></script>
		<script type="text/javascript" src="plugins/zTree/2.6/jquery.ztree-2.6.min.js"></script>
		<script src="plugins/bootstrap/js/bootstrap-table.js"></script>
		<script src="plugins/bootstrap/js/bootstrap-table-zh-CN.js"></script>
		
		 <script src="plugins/json2.js" type="text/javascript"></script>
		<script src="plugins/treeTable/jquery.treeTable.min.js"></script>
		<script src="plugins/mustache.min.js" type="text/javascript"></script>
		<script src="plugins/jeesite.min.js" type="text/javascript"></script>
		<script type="text/javascript">
		$(top.hangge());
		
		$(document).ready(function() {
			var areaDate;
			$.ajax({
				url : "<%=basePath%>area/getAreaList.do",
				type : "post",
				async: false,
				 /* data : {
					'platformId' : stationId
				}, */ 
				dataType: 'json', 
			    success:function(data){
			    	areaDate= data.areaList;
			    }
			});
			$("#treeTableList").html("");
			//alert(areaDate);
			var text= "";
			for(var i=0;i<areaDate.length;i++){
				if(areaDate[i].parent.id=='0'){
					if(areaDate[i].remarks==null){
						areaDate[i].remarks="无";
					}
					
					text+='<tr id="'+areaDate[i].id+'" pid="'+areaDate[i].parent.id+'"><td>'+areaDate[i].name+'</td><td style="text-align: center;">'+areaDate[i].code+'</td><td style="text-align: center;">'+findType(areaDate[i].type)+'</td><td style="text-align: center;">'+areaDate[i].remarks+'</td><td style="text-align: center;"><a class="btn btn-mini btn-info" title="编辑" onclick="edit(\''+areaDate[i].id+'\');"><i class="icon-edit"></i></a>&nbsp;<a class="btn btn-mini btn-danger" title="删除" onclick="del(\''+areaDate[i].id+'\');"><i class="icon-trash"></i></a></td></tr>'				
					text = findSubArea(areaDate, areaDate[i].id, text);
				}
				//text+="<tr><td>"+areaDate[i].name+"</td><td>"+areaDate[i].code+"</td><td>"+areaDate[i].type+"</td><td>"+areaDate[i].remarks+"</td><td></td></tr>"
			}
			$("#treeTableList").append(text);
			
			$("#treeTable").treeTable({ expandable: true,expandLevel:5 });
			
		});
		
		function findSubArea(areaDate,id,text){
			for(var i=0;i<areaDate.length;i++){
				if(areaDate[i].parent.id==id){
					if(areaDate[i].remarks==null){
						areaDate[i].remarks="无";
					}
					var type = findType(areaDate[i].type);
					if(text!=''){
						text+='<tr id="'+areaDate[i].id+'" pid="'+areaDate[i].parent.id+'"><td style="height: 35px;">'+areaDate[i].name+'</td><td style="text-align: center;">'+areaDate[i].code+'</td><td style="text-align: center;">'+findType(areaDate[i].type)+'</td><td style="text-align: center;">'+areaDate[i].remarks+'</td><td style="text-align: center;"><a class="btn btn-mini btn-info" title="编辑" onclick="edit(\''+areaDate[i].id+'\');"><i class="icon-edit"></i></a>&nbsp;<a class="btn btn-mini btn-danger" title="删除" onclick="del(\''+areaDate[i].id+'\');"><i class="icon-trash"></i></a></td></tr>'
						text = findSubArea(areaDate, areaDate[i].id, text);
					}
				}
			}
			return text;
		}
		
		function findType(num){
			var type;
			 if(num=='1'){
				type="国家";
			}else if(num=='2'){
				type="省份、直辖市";
			}else if(num=='3'){
				type="地市";
			}else if(num=='4'){
				type="县区";
			}else {
				type="其他"
			}
			return type;
		}
		
		//检索
		function search(){
			top.jzts();
			$("#Form").submit();
		}
		
		//新增
		function add(){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="新增";
			 diag.URL = '<%=basePath%>area/goAdd.do';
			 diag.Width = 450;
			 diag.Height = 475;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					 if('${page.currentPage}' == '0'){
						 top.jzts();
						 setTimeout("self.location=self.location",100);
					 }else{
						 nextPage(${page.currentPage});
					 }
				}
				diag.close();
			 };
			 diag.show();
		}
		
		//删除
		function del(Id){
			bootbox.confirm("确定要删除吗?", function(result) {
				if(result) {
					top.jzts();
					var url = "<%=basePath%>area/delete.do?ID="+Id+"&tm="+new Date().getTime();
					$.get(url,function(data){
						if("${page.currentPage}"==0){
						 	location.reload();
						 }else{
						 	alert("删除失败");
						 }
					});
				}
			});
		}
		
		//修改
		function edit(Id){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="编辑";
			 diag.URL = '<%=basePath%>area/goEdit.do?ID='+Id;
			 diag.Width = 450;
			 diag.Height = 475;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					 //nextPage(${page.currentPage});
					  if(${page.currentPage}==0){
					 	location.reload();
					 }else{
					 	alert("修改失败");
					 }
				}
				diag.close();
			 };
			 diag.show();
		}
		</script>
		
		<script type="text/javascript">
		
		$(function() {
			
			//下拉框
			$(".chzn-select").chosen(); 
			$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
			
			//日期框
			$('.date-picker').datepicker();
			
			//复选框
			$('table th input:checkbox').on('click' , function(){
				var that = this;
				$(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function(){
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});
					
			});
			
		});
		
		
		//批量操作
		function makeAll(msg){
			bootbox.confirm(msg, function(result) {
				if(result) {
					var str = '';
					for(var i=0;i < document.getElementsByName('ids').length;i++)
					{
						  if(document.getElementsByName('ids')[i].checked){
						  	if(str=='') str += document.getElementsByName('ids')[i].value;
						  	else str += ',' + document.getElementsByName('ids')[i].value;
						  }
					}
					if(str==''){
						bootbox.dialog("您没有选择任何内容!", 
							[
							  {
								"label" : "关闭",
								"class" : "btn-small btn-success",
								"callback": function() {
									//Example.show("great success");
									}
								}
							 ]
						);
						
						$("#zcheckbox").tips({
							side:3,
				            msg:'点这里全选',
				            bg:'#AE81FF',
				            time:8
				        });
						
						return;
					}else{
						if(msg == '确定要删除选中的数据吗?'){
							top.jzts();
							$.ajax({
								type: "POST",
								url: '<%=basePath%>area/deleteAll.do?tm='+new Date().getTime(),
						    	data: {DATA_IDS:str},
								dataType:'json',
								//beforeSend: validateData,
								cache: false,
								success: function(data){
									 $.each(data.list, function(i, list){
											nextPage(${page.currentPage});
									 });
								}
							});
						}
					}
				}
			});
		}
		
		//导出excel
		function toExcel(){
			window.location.href='<%=basePath%>area/excel.do';
		}
		</script>
		
	</body>
</html>

